package com.tz.actions;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.tz.entity.Product;
import com.tz.service.ProductService;
import com.tz.util.MyAcUtil;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 16-7-19.
 */
@Namespace("/product")
@ParentPackage("json-default")
public class ProductAction extends ActionSupport {

    @Autowired
    private ProductService productService;

    private List<Product> result;
    private String catename;

    public ProductAction() {

    }

    @Action( value = "list", results = {
            @Result(type = "json" ,params = {"root", "result"})
    })


    public String list() {

        result = productService.findProduct();
        return SUCCESS;
    }
    @Action( value = "details", results = {
            @Result(location = "/product.jsp")
    })
    public String details() {

        result = productService.findProductBy(catename);
        return SUCCESS;
    }

    public List<Product> getResult() {
        return result;
    }

    public void setResult(List<Product> result) {
        this.result = result;
    }

    public String getCatename() {
        return catename;
    }

    public void setCatename(String catename) {
        this.catename = catename;
    }
}
